package whu.cn.whushare.ui.common;


import android.app.Activity;
import android.view.View;
import android.widget.SearchView;

import com.androidplus.util.StringUtil;

import whu.cn.whushare.ui.main.MainTabActivity;
import whu.cn.whushare.ui.main.known.SearchHistoryPop;

public abstract class MainReShowFragment extends BaseFragment {
    private MainTabActivity mainTabActivity;

    @Override
    //当MainReShowFragment被添加到非MainTabActivity实例时抛出异常
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (activity instanceof MainTabActivity)
            mainTabActivity = (MainTabActivity) activity;
        else
            throw new IllegalArgumentException("fragment used in wrong activity");
    }

    /**
     * 获得顶部菜单条：先初始化TopBar，并为返回键设置事件监听器，然后返回该TopBar
     * @param root - 父控件
     * @return view - 返回当前TopBar
     */
    protected View getTopBar(View root, int topId) {
        View view = super.initTopBar(root, topId);
        mTopBar.goBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goBack(mainTabActivity);
            }
        });

        return view;
    }

    /**
     * 获得不带返回按钮的顶部菜单条
     * @param root - 父控件
     * @return view - 返回当前TopBar
     */
    protected View getTopBarWithoutBack(View root, int topId) {
        View view = super.initTopBar(root, topId);
        mTopBar.goBack.setVisibility(View.GONE);
        return view;
    }

    public void onReShow(MainTabActivity mainTabActivity) {
    }

    public boolean goBack(MainTabActivity mainTabActivity) {
        mainTabActivity.goBack();
        return false;
    }
}
